import Vue from "vue";
import VueRouter from "vue-router";
import { getToken } from "@/utils/storage";
Vue.use(VueRouter);

const routes = [

{
  path: '/',
  name: 'denglu',
  component:()=>import('../mjal/denglu.vue')
},
{
  path: '/zhuce',
  name: 'zhuce',
  component:()=>import('../mjal/zhuce.vue')
},
{
  path: '/xiangqing',
  name: 'xiangqing',
  component:()=>import('../mjal/xiangqing.vue')
},
{
  path: '/layout',
  name: 'Layout',
  redirect:'/shouye',
  component:()=>import('../mjal/layout.vue'),
 children:[
  {
    path: '/shouye',
    name: 'shouye',
    component:()=>import('../mjal/shouye.vue')
},
{
  path: '/wode',
  name: 'wode',
  component:()=>import('../mjal/wode.vue')
},
{
  path: '/xihuan',
  name: 'xihuan',
  component:()=>import('../mjal/xihuan.vue')
},
{
  path: '/shoucang',
  name: 'shoucang',
  component:()=>import('../mjal/shoucang.vue')
},
 ]


},

  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   /*  */
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')//路由懒加载
  // }
];

const router = new VueRouter({
  routes,
});

// const white = ["/login", "/register"];

// router.beforeEach((to, from, next) => {
//   var token = getToken();

//   if (token) {
//     console.log(token, "11token");
//     next();
//   } else {
//     console.log(token, "222token");
//     if (white.includes(to.path)) {
//       next();
//     } else {
//       next("/login");
//     }
//   }

// });

// let originPush = VueRouter.prototype.push;
// let originReplace = VueRouter.prototype.replace;
// VueRouter.prototype.push = function (location, res, rej) {
//   if (res && rej) {
//     originPush.call(this, location, res, rej);
//   } else {
//     originPush.call(
//       this,
//       location,
//       () => { },
//       () => { }
//     );
//   }
// };

// VueRouter.prototype.replace = function (location, res, rej) {
//   if (res && rej) {
//     originReplace.call(this, location, res, rej);
//   } else {
//     originReplace.call(
//       this,
//       location,
//       () => { },
//       () => { }
//     );
//   }
// };

export default router;
